package name.wilbur.course.db.bigone.service.impl;

import name.wilbur.course.db.bigone.dao.DAOFactory;
import name.wilbur.course.db.bigone.dao.impl.CityDAO;
import name.wilbur.course.db.bigone.dao.impl.ICityDAO;
import name.wilbur.course.db.bigone.dao.impl.IOccupationDAO;
import name.wilbur.course.db.bigone.dao.impl.IProfileDAO;
import name.wilbur.course.db.bigone.dao.impl.IUserDAO;
import name.wilbur.course.db.bigone.dao.impl.OccupationDAO;
import name.wilbur.course.db.bigone.dao.impl.ProfileDAO;
import name.wilbur.course.db.bigone.dao.impl.UserDAO;
import name.wilbur.course.db.bigone.model.City;
import name.wilbur.course.db.bigone.model.Occupation;
import name.wilbur.course.db.bigone.model.Profile;
import name.wilbur.course.db.bigone.model.User;
import name.wilbur.course.db.bigone.service.IUserService;

public class UserService implements IUserService {
	private static IUserDAO userDAO;
	private static ICityDAO cityDAO;
	private static IOccupationDAO occupationDAO;
	private static IProfileDAO profileDAO;
	
	public UserService() {
	}
	
	public boolean removeUser(int userID) {
		return getUserDAO().delete(userID);
	}
	
	public void removeUsers(User[] users) {
		getUserDAO().delete(users);
	}
	
	public User[] getAllUsersExcept(int userID) {
		return getUserDAO().findAllUsersExcept(userID);
	}
	
	public User getUser(int userID) {
		return (User) getUserDAO().findByPK(userID);
	}
	
	public User getUser(String name) {
		return (User) getUserDAO().findByName(name);
	}
	public Profile getProfile(int userID) {
		return (Profile) getProfileDAO().findProfileByUserID(userID);
	}
	
	public boolean createProfile(Profile profile) {
		return getProfileDAO().create(profile);
	}
	
	public boolean updateProfile(Profile profile) {
		return getProfileDAO().update(profile);
	}
	
	public City getUserCity(int cityID) {
		return (City)getCityDAO().findByPK(cityID);
	}
	
	public Occupation getUserOccupation(int occupationID) {
		return (Occupation)getOccupationDAO().findByPK(occupationID);
	}
	
	public IUserDAO getUserDAO() {
		if (userDAO == null)
			userDAO = (UserDAO) DAOFactory.createDAO(UserDAO.class);
		return userDAO;
	}
	public ICityDAO getCityDAO() {
		if (cityDAO == null)
			cityDAO = (CityDAO) DAOFactory.createDAO(CityDAO.class);
		return cityDAO;
	}
	public IOccupationDAO getOccupationDAO() {
		if (occupationDAO == null)
			occupationDAO = (OccupationDAO) DAOFactory.createDAO(OccupationDAO.class);
		return occupationDAO;
	}
	public IProfileDAO getProfileDAO() {
		if (profileDAO == null)
			profileDAO = (ProfileDAO) DAOFactory.createDAO(ProfileDAO.class);
		return profileDAO;
	}
}
